package com.ruoyi.project.system.threadpoolAndAsync.service.impl;


import com.ruoyi.project.system.threadpoolAndAsync.service.MyAsyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @program: test_demo
 * @description: 异步发送消息
 * @author: yanghua
 * @create: 2021-10-09 10:14
 **/
@Service
@Slf4j
public class MyAsyncServiceImpl implements MyAsyncService {

    @Override
    @Async("threadPoolTaskExecutor")  //使用taskExecutor线程池,taskExecutor由ThreadPoolConfig配置类中@bean注解中的名字相同
    @Transactional(rollbackFor = RuntimeException.class)
    public String sms() {
        log.info("======线程名======="+Thread.currentThread().getName());
        try {
            log.info("正在发送短信===等待30秒钟===");
            Thread.sleep(30000);
        } catch (Exception e) {

        }
        log.info("======我这段代码是上面执行完再执行还是上面代码执行中执行=======");//测试结果是上面的代码执行完毕才会运行
        return "短信发送完成";
    }
}
